<?php
    function get_client_ip() {
        if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
            $ip = getenv("HTTP_CLIENT_IP");
        else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), 
    "unknown"))
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
            $ip = getenv("REMOTE_ADDR");
        else if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] 
    && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
            $ip = $_SERVER['REMOTE_ADDR'];
        else
            $ip = "unknown";
        echo $ip;
        return ($ip);
    }

    function get_client_address($ip) {
        $url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
        $data = json_decode(file_get_contents($url)); //调用淘宝接口获取信息
        // echo $data;
        // var_dump( $data );
        echo preg_replace('/[\x{7701},\x{5E02}]/u', '', $data->{'data'}->{'region'});
        echo preg_replace('/[\x{7701},\x{5E02}]/u', '', $data->{'data'}->{'city'});
        // echo $data->{'data'}->{'city'};
        // echo '------city'.json_encode( $data['country'] );
    }

    function get_weather( $cityCode ) {
        $url = "http://m.weather.com.cn/data/" . $cityCode . ".html";
        $data = json_decode(file_get_contents($url))->{'weatherinfo'}; 
        $output = array('date' => $data->{'date_y'}, 'city' => $data->{'city'}, 'temp' => $data->{'temp1'}, 'weather' => $data->{'weather1'});
        echo json_encode($output);
        // var_dump($data);
        // echo $data;
        // var_dump( $data );
        // echo preg_replace('/[\x{7701},\x{5E02}]/u', '', $data->{'data'}->{'region'});
    }
    // echo json_encode('省');
    // $ip = get_client_ip();
    // get_client_address('58.22.135.255');
    get_weather( '101230201' )
?>